import request from '../utils/request'

export function login(data) {
  return request({
    url: '/user/login',
    method: 'post',
    data: {
      account: data.account,
      password: data.password
    }
  })
}

export function register(data) {
  return request({
    url: '/user/register',
    method: 'post',
    data: {
      account: data.account,
      password: data.password,
      name: data.name
    }
  })
}

export function getUserInfo(account) {
  return request({
    url: '/user',
    method: 'get',
    params: { account }
  })
}

export function searchUserByName(namePattern) {
  return request({
    url: '/user/like',
    method: 'get',
    params: { namePattern }
  })
}

export function updateUser(data) {
  return request({
    url: '/user',
    method: 'put',
    data: {
      account: data.account,
      password: data.password,
      name: data.name
    }
  })
}

export function changePassword(data) {
  return request({
    url: '/user/password',
    method: 'put',
    data: {
      account: data.account,
      oldPassword: data.oldPassword,
      newPassword: data.newPassword
    }
  })
} 